

//
//  CZComments.swift
//  GZWeibo007
//
//  Created by 陈华 on 15/12/24.
//  Copyright © 2015年 Apple. All rights reserved.
//

import UIKit

class CZComments: NSObject {

    
    //MARK: - 定义属性
    
    ///评论创建时间
    var created_at: String?
    
    ///评论的内容
    var text: String?
    
    ///评论作者
    var user: CZUser?
    
    ///评论的来源
    var source: String?
    
    ///微博
    
    var status: CZStatus?
    
    ///评论ID
    
    var id: Int = 0
    
    //MARK: - 定义方法
    
    init(dict: [String: AnyObject]) {
        super.init()
        
        setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) { }
    
    //<模型嵌套字典
    override func setValue(value: AnyObject?, forKey key: String) {
        super.setValue(value, forKey: key)
        
        if key == "user"{
            let ve = value as! [String: AnyObject]
            user = CZUser(dict: ve)
        }else{
            super.setValue(value, forKey: key)
        }
    }
    

    
    /**
     返回某条微博的评论列表
     
     :param: id       微博ID
     :param: since_id 下拉刷新参数 默认值0
     :param: max_id   上拉加载参数 默认值0
     :param: count    一次加载刷新微博数量
     :param: finished 完成回调
     */
  class func ZHLoadDiscussData(id: Int, since_id: Int, max_id: Int, count: Int, finished:(comments: [CZComments]?, error: NSError?) -> ()){
        
        CZNetworkTool.sharedInstance.loadDiscussEntryData(id, since_id: since_id, max_id: max_id, count: count, finished: { (result, error) -> () in
            
            if error != nil || result == nil {
                finished(comments: nil, error: error)
                return
            }
            
           
            if let array = result?["comments"] as? [[String: AnyObject]] {
                
                var comments = [CZComments]()
                
                for dcit in array {
                  
                    let comment = CZComments(dict: dcit)
                    
                    comments.append(comment)
                }
                    finished(comments: comments, error: nil)
            }
        })
    }
    
}









